# 1 "init.c"
# 1 "/home/diego/sodium/usr//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "init.c"
# 1 "../include/usr/libsodium.h" 1







# 1 "../include/kernel/syscall.h" 1







# 1 "../include/kernel/signal.h" 1
# 9 "../include/kernel/syscall.h" 2
# 1 "../include/kernel/semaforo.h" 1
# 20 "../include/kernel/semaforo.h"
typedef struct
{
 int inicializado;
 int valor;
 unsigned long int head;
 unsigned long int tail;

 unsigned long int procesosEnCola;

 unsigned long int cola[5];
 unsigned long int pshared;
}semaforo;





typedef struct
{
 int sem_id;
}sem_t;





typedef struct{
 int pshared;
 unsigned int value;
} sem_init_params;


void vFnEncolarProceso(semaforo *sem, unsigned long int uliId);


void vFnInicializaCola(unsigned long int *cola);


int iFnHayProcesoEnEspera(semaforo *sem);


unsigned long int uliFnDesencolarProceso(semaforo *sem);


void vFnInicializarSemaforos();
# 77 "../include/kernel/semaforo.h"
int iFnSemInit(sem_t *sem, int pshared, unsigned int value);
# 86 "../include/kernel/semaforo.h"
int iFnSemClose(sem_t *sem);
# 106 "../include/kernel/semaforo.h"
int iFnSemWait(sem_t *sem);
# 116 "../include/kernel/semaforo.h"
int iFnSemPost(sem_t *sem);

int validaExistenciaSemaforo(sem_t *sem);


int agregarSemaforoAlSistema(int pshared, unsigned int value);

void vFnVerSemaforos();
# 10 "../include/kernel/syscall.h" 2
# 1 "../include/kernel/shm.h" 1
# 18 "../include/kernel/shm.h"
typedef unsigned int size_t;
typedef int key_t;
typedef int bool;


typedef struct _stuMemoriasAtachadas_
{
 bool utilizada;
 int posicionEnShMem;
 int posicionEnAttach;
}stuMemoriasAtachadas;


typedef struct _attach_
{
 int pid;
 void * ptrShAddr;

}attach;


typedef struct _shMem_
{
 key_t key;
 unsigned long int tamanio;
 attach procAtt[5];
 bool declarada;
}shMem;

shMem memoriasCompartidas[5];




int iFnShmGet(key_t key, size_t size);


int iFnShmAt(int shmid, void * shmAddr);


int iFnShmDt(int shmid);

int iFnShmDtProc(int shmid, unsigned int uiPid);
int iFnShmDtAllProc(unsigned int uiPid);

unsigned long ulFnMaxDirShmProc(unsigned int uiPid);

void vFnInicializarShms();
void vFnVerShm();




void vFnCopiarVariablesCompartidas();



void vFnCopiarVariable(void * dest, void * src, size_t tamanio);
# 11 "../include/kernel/syscall.h" 2
# 1 "../include/kernel/tiempo.h" 1







# 1 "../include/kernel/definiciones.h" 1
# 14 "../include/kernel/definiciones.h"
# 1 "../include/usr/tipos.h" 1
# 15 "../include/usr/tipos.h"
typedef unsigned int dword;
typedef unsigned short word;
typedef unsigned char byte;

typedef unsigned char u8;
typedef signed char s8;
typedef unsigned short u16;
typedef signed short s16;
typedef unsigned int u32;
typedef signed int s32;


typedef struct _u80 { unsigned int word[20]; } u80;
# 15 "../include/kernel/definiciones.h" 2
# 62 "../include/kernel/definiciones.h"
char stArgAux[128];
# 9 "../include/kernel/tiempo.h" 2
# 53 "../include/kernel/tiempo.h"
typedef unsigned long int time_t;
typedef unsigned long int clock_t;





typedef struct{

        clock_t tms_utime;


        clock_t tms_stime;


        clock_t tms_cutime;


        clock_t tms_cstime;
} tms;





typedef struct{

        int tz_minuteswest;


        int tz_dsttime;
} timezone;





typedef struct{

        unsigned long int tv_sec;


        unsigned long int tv_usec;
} timeval;





typedef struct{

        timeval it_interval;


        timeval it_value;
} itimerval;





typedef struct{

        int modes;


 long offset;


 long freq;


 long maxerror;


 long esterror;


 int status;


 long constant;


 long precision;


 long tolerance;


 timeval time;


 long tick;
} timex;





typedef struct{

        long int tv_sec;


        long int tv_nsec;
} timespec;
# 12 "../include/kernel/syscall.h" 2
# 195 "../include/kernel/syscall.h"
enum __ptrace_request {
 PTRACE_TRACEME,
 PTRACE_PEEKTEXT,
 PTRACE_PEEKDATA,
 PTRACE_PEEKUSER,
 PTRACE_POKETEXT,
 PTRACE_POKEDATA,
 PTRACE_POKEUSER,
 PTRACE_GETREGS,
 PTRACE_GETFPREGS,
 PTRACE_SETREGS,
 PTRACE_SETFPREGS,
 PTRACE_CONT,
 PTRACE_KILL,
 PTRACE_ATTACH,
 PTRACE_DETACH
};


typedef struct {
 int iPid;
 void *pvAddr;
 void *pvData;
}__ptrace_param;



typedef struct _stuRegs_
{
  long ebx;
  long ecx;
  long edx;
  long esi;
  long edi;
  long ebp;
  long eax;
  int xds;
  int xes;
  long orig_eax;
  long eip;
  int xcs;
  long eflags;
  long esp;
  int xss;
} stuRegs;






long lFnSysExit( int status );
long lFnSysFork();
long lFnSysTest( long num );
long lFnSysRead( int, void *buf, size_t count );
long lFnSysWrite( int, const void *buf, size_t count );
long lFnSysWaitPid( int pid, int *status, int options );
long lFnSysExecve( const char *filename, char *argv[], char *envp[] );
long lFnSysTime( long *t );
long lFnSysGetPid();
long lFnSysKill( int pid, int sig );
long lFnSysGetPPid();
long lFnSysReboot( int flag );
long lFnSysSodiumCallgate(int iOpcion, int iPar1, int iPar2);
long lFnSysBrk(unsigned long);
long lFnSysSBrk(unsigned long);
long lFnSysSemInit( sem_t *sem, sem_init_params * params);
long lFnSysSemPost( sem_t *sem );
long lFnSysSemWait( sem_t *sem );
long lFnSysSemClose( sem_t *sem );
long lFnSysShmGet( key_t key, size_t size );
long lFnSysShmAt( int shmid, void * shmAddr );
long lFnSysShmDt( key_t key );

int iFnSysSumar(int a, int b, int * res);



long lFnSysNice( int );
long lFnSysGetpriority( int, int );
long lFnSysSetpriority( int, int, int );
long lFnSysClone(stuRegs *,int flags);


long lFnSysIdle();



long lFnSysSchedSetParam(int p);
long lFnSysSchedGetParam();
long lFnSysSchedSetScheduler(int p);
long lFnSysSchedGetScheduler();
long lFnSysSchedYield();
long lFnSysSchedGetPriorityMax();
long lFnSysSchedGetPriorityMin();
long lFnSysSchedRrGetInterval();





long lFnSysStime(time_t *newtime);
long lFnSysTimes(tms *ptmsbuffer);
long lFnSysGettimeofday(timeval *ptimervalTp, timezone *ptimezoneTzp);
long lFnSysSettimeofday(timeval *ptimevalTp, timezone *ptimezoneTzp);
long lFnSysGettimer(int iWhich, itimerval *pitimervalValue);
long lFnSysSettimer(int iWhich, itimerval const *pcnitimervalValue, itimerval *ptimervalOvalue);
long lFnSysAdjtimex(timex *ptimexBuffer);
long lFnSysNanosleep(timespec const *pcntimespecRequested_time, timespec *ptimespecRemaining);



long lFnSysPtrace( int request, void *pvDirParam );





unsigned long ulFnSysBrk(unsigned long brk);
# 9 "../include/usr/libsodium.h" 2

# 1 "../include/usr/mem_part_usuario.h" 1







void* malloc(long int);
void* realloc(long int, unsigned long);
int free(long int);
void iFnListar();

long int liHeapEndPorcentajes;

int iFnInicializarHeapUsuario();
# 11 "../include/usr/libsodium.h" 2
# 1 "../include/usr/enviroment.h" 1







int iFnInicializarEnviromentUsuario(char**);
int iFnEnvObtenerValorNumerico(char *);
int iFnEnvCompararVariable(char *, char *);
int iFnEnvCompararValor(char *, char *);
int iFnEnvSet(char* );
int iFnEnvUnSet(char *);
int iFnEnvBuscarPosicion(char *);
int iFnEnvListarEnviroment();
int iFnEnvCompararValorDeVariable(char *, char *);
int iFnEnvObtenerValorNumericoDeVariable(char*);
char** pstFnEnvObtenerEnviroment();

int iEnvSoloLectura;
int iEnviromentInicializado;
int iCantAsignaciones;
char** pstEnviroment;
# 12 "../include/usr/libsodium.h" 2
# 1 "../include/usr/sodstring.h" 1







inline unsigned char* memcpy(unsigned char *ucpDestino,
      unsigned char *ucpOrigen,
      unsigned int uiTamanio);

inline unsigned char* memcero(unsigned char *ucpDirInicio,
                  unsigned int uiTamanio );

int iFnLongitudCadena (const char*);
int iFnStrcmp(const char*, const char*);
int iFnStrlen(const char*);
int iFnStrcpy(char*, const char*);
int iFnNumStrcmp(const char*, const char*);
# 13 "../include/usr/libsodium.h" 2
# 23 "../include/usr/libsodium.h"
extern int errno;






void exit( int iStatus );
int fork();
int read( int iFd, void *vpBuffer, size_t uiTamanio );
int write( int iFd, const void *covpBuffer, size_t uiTamanio );
long systest( long iNumero );
int waitpid( int iPid, int *piStatus, int iOptions );
int execve( const char *stNombreArchivo, char *const argv[], char *const envp[] );
long time( long *liTiempo );
long getpid();
long sodiumcg(int iOpcion, int iPar1, int iPar2);
long lista_porcentajes(int ptrPorcentaje);
long char2int(char* caracter);
int kill( int iPid, int iSignal );
long getppid();
int reboot( int iflag );
int sem_init( sem_t *sem, int pshared, unsigned int value );
int sem_post( sem_t *sem );
int sem_wait( sem_t *sem );
int sem_close( sem_t *sem );
int shmget( key_t key, size_t size );
int shmat( int shmid, void * shmAddr );
int shmdt( int shmid );
int sumar(int a, int b);
long nice(int iIncremento);
long getpriority(int which, int who);
long setpriority(int,int,int);
long clone(int (*fn)(void * args),void * child_stack,int flags, void * arg);


int stime(time_t *newtime);
clock_t times(tms *ptmsBuffer);
int gettimeofday(timeval *ptimevalTp, timezone *ptimezoneTzp);
int settimeofday(timeval *ptimevalTp, timezone *ptimezoneTzp);
int gettimer(int iWhich, itimerval *pitimervalValue);
int settimer(int iWhich, itimerval const *pcnItimervalValue, itimerval *pitimervalOvalue);
int adjtimex(timex *ptimexBuffer);
int nanosleep(timespec const *pcnTimespecRequested_time, timespec *ptimespecRemaining);


int idle();



int sched_setparam( int p);
int sched_getparam();
int sched_setscheduler( int p);
int sched_getscheduler();
int sched_yield();
int sched_get_priority_max();
int sched_get_priority_min();
int sched_rr_get_interval();


int ptrace( int iRrequest, int iPid, void *pvAddr, void *pvData );


unsigned long __brk (unsigned long limite);

unsigned long __sbrk (unsigned long limite);



typedef char* va_list;
# 2 "init.c" 2
# 1 "../include/usr/init.h" 1
# 3 "init.c" 2
# 15 "init.c"
int main(int argc, char* argv[]){

    int iPid_Hijo = 0;
 long int liHeapSize;
    int i;

    char** pstArgv;
 char** pstEnvp;


    pstArgv = pstFnObtenerArgumentos("SHELLUSR");
    if(pstArgv == -1) return -1;



 pstEnvp = pstFnEnvObtenerEnviroment();
    if(pstEnvp == -1) return -1;




   liHeapSize = iFnEnvObtenerValorNumericoDeVariable("TamanioHeapUsuario");
   if(liHeapSize <= 0)
     {
     iFnImprimir("\n[!] Variable de entorno \"TamanioHeapUsuario\" no esta definida, utilizando tamanio de heap por defecto (100kb)");
  iFnSodiumCallgate(51,100000,0);

  }
   iFnSodiumCallgate(51,liHeapSize,0);

   while(1)
    {
   iPid_Hijo = fork();
   if(iPid_Hijo == 0) {
   if(execve("SHELLUSR.BIN",pstArgv,pstEnvp) < 0) exit(1);
   }
   waitpid(iPid_Hijo,0,0);
    }

  return -1;
}
